package com.cheng.io.reader;

import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * 文件字符输入流
 */
public class FileReaderTest01 {
    public static void main(String[] args) {
        try (
                Reader reader = new FileReader("D:\\code\\java-study\\java-study\\io\\resources\\特性.txt");
        ) {
            // Test reader.read(char[] c) 一次读取char[].len个字符
            /*char[] chars = new char[2];
            int readCount = 0;
            while ((readCount = reader.read(chars)) != -1) {
                System.out.print(new String(chars, 0, readCount));
            }*/

            // Test read(char[] c, int off, int len) 一次读取len个字符并从char[]中off下标中添加字符
            /*char[] chars1 = new char[10];
            int readCount = 0;
            while ((readCount = reader.read(chars1, 2, 5)) != -1) {
                System.out.print(new String(chars1, 0, readCount));
            }*/

            // Test skip(long n) 跳过读取的字符数
            reader.skip(2);
            char[] chars = new char[2];
            int readCount = 0;
            while ((readCount = reader.read(chars)) != -1) {
                System.out.print(new String(chars, 0, readCount));
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
